package com.jieshen.chat;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class Server {
    //创建集合对象，存储每一个连接进来的客户端
    public static List<MyChannel> list = new ArrayList<MyChannel>();

    public static void main(String[] args) {
        System.out.println("---------------服务器已开启---------------");
        try {
            ServerSocket server = new ServerSocket(9999);


//            DataInputStream dis = new DataInputStream(socket.getInputStream());
//            DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
            while (true) {
//                String str = dis.readUTF();
//                System.out.println("客户端发送的数据为:-->"+str);
////                dos.writeUTF("服务器收到:"+str);
//                Send send = new Send(socket);
//                String message = send.getMessage();
//                dos.writeUTF("服务器: "+message);

                Socket socket = server.accept();
                MyChannel channel = new MyChannel(socket);
                list.add(channel);
                new Thread(channel).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
        }
    }
}
